package com.lilanz.facepass.controller.member;

import com.alibaba.fastjson.JSONObject;
import com.lilanz.facepass.entity.client.Client;
import com.lilanz.facepass.service.impl.ClientServiceImpl;
import com.lilanz.facepass.service.impl.HTTPServiceImpl;
import com.lilanz.facepass.util.Json;
import com.lilanz.facepass.util.ToolUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@RestController()
@RequestMapping("/member")
@PropertySource({"classpath:application.properties"})//引入外部资源文件
public class MemberController {
    @Value("${member.get-xiaoke-list}")
    private String getXiaokeList;

    @Value("${member.get-member-list}")
    private String getMemberList;

    @Value("${member.member-register}")
    private String memberRegister;


    @Resource
    private ClientServiceImpl clientService;
    @Resource
    private HTTPServiceImpl httpService;


    @GetMapping("/memberRegister")
    public JSONObject getMemberRegister(@RequestParam String areacode, @RequestParam String personName, @RequestParam String phone,String personTypeId ) {
        Client client = clientService.selectClient();
        Map<String, String> map = new HashMap<>();
        map.put("phoneNo", client.getPhoneNo());
        map.put("password", client.getPassword());
        map.put("vi", client.getVi());
        map.put("areacode", areacode);
        map.put("personName", personName);
        map.put("phone", phone);
        map.put("personTypeId", personTypeId);
        map.put("key", ToolUtil.getKey(map));//这个key一定放最后一个
        JSONObject result = httpService.sendPost(memberRegister, client.getToken(), map);
        return Json.success(0, "ok", result);
    }


    @PostMapping("/getMemberList")
    public JSONObject getMemberList(@RequestParam String areacode, @RequestParam String pagenumber) {
        Client client = clientService.selectClient();
        Map<String, String> map = new HashMap<>();
        map.put("phoneNo", client.getPhoneNo());
        map.put("password", client.getPassword());
        map.put("vi", client.getVi());
        map.put("areacode", areacode);
        map.put("pagenumber", pagenumber);
        map.put("key", ToolUtil.getKey(map));//这个key一定放最后一个
        JSONObject result = httpService.sendPost(getMemberList, client.getToken(), map);
        return Json.success(0, "ok", result);
    }


    @PostMapping("/getXiaokeList")
    public JSONObject getXiaokeList(@RequestParam String areacode, @RequestParam String pagenumber, String startdate) {
        Client client = clientService.selectClient();
        Map<String, String> map = new HashMap<>();
        map.put("phoneNo", client.getPhoneNo());
        map.put("password", client.getPassword());
        map.put("vi", client.getVi());
        map.put("areacode", areacode);
        map.put("pagenumber", pagenumber);
        map.put("startdate", startdate);
        map.put("key", ToolUtil.getKey(map));//这个key一定放最后一个
        JSONObject result =httpService.sendPost(getXiaokeList, client.getToken(), map);
        return Json.success(0, "ok", result);
    }


}
